package krillr.Util;
import robocode.*;
import robocode.util.Utils;
import java.util.*;
import krillr.Predictors.*;
import java.awt.Color;
import java.awt.geom.*;

/**
 * UnitTracker - AdvancedRobot tracking class for Robocode
 * 
 * @author Aaron M. Krill
 * @version 0.1
 */
public class SelfTracker extends Tracker {    
    public SelfTracker() {
        return;
    }
    
    /**
     * Constructs a point at the specified x and y coordinates.
     * 
     * @param e - the ScannedRobotEvent to us by the Battlefield tracker or the bot
     * @param b - the parent robot
     */
    public SelfTracker(KrillBot b) {
        bot = b;
        fieldRectangle = new Rectangle2d(0, 0, b.getBattleFieldWidth(), b.getBattleFieldHeight());
        name = bot.getName();
        setVector(new Vector2d(bot.getHeadingRadians(), bot.getVelocity()));
        setEnergy(bot.getEnergy());
        setLocation(new Point2d(bot.getX(), bot.getY()));
        Predictor p = new GuessFactorA(bot, this);
        p.update();
        predictors.add(p);
    }
        
    public void run() {
        if(hasFired()) {
            oldEnergy = energy;
            double be = bulletEnergy();
            Point2d bulletLocation = lastKnownLocation();
            double enemyHeading = heading();
            double bulletHeading = KrillUtil.getBearing(bulletLocation, new Point2d(bot.getX(), bot.getY())) + enemyHeading;
            BulletTracker bullet = new BulletTracker(bulletLocation, bulletHeading, be, bot.getTime());
            bullets.add(bullet);
        }
        
        checkBullets();
    }
    
    public void update() {
        setVector(new Vector2d(bot.getHeadingRadians(), bot.getVelocity()));
        setEnergy(bot.getEnergy());
        setLocation(new Point2d(bot.getX(), bot.getY()));
    }
}